﻿using Fast.Validation;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Net;

namespace Fast.ExceptionHandling
{
    /// <summary>
    /// Http状态码查找器
    /// </summary>
    public class DefaultHttpStatusCodeFinder : IHttpStatusCodeFinder, ITransientDependency
    {
        public virtual HttpStatusCode GetStatusCode(HttpContext httpContext, Exception exception)
        {
            if (exception is FastValidationException)
            {
                return HttpStatusCode.BadRequest;
            }

            if (exception is NotImplementedException)
            {
                return HttpStatusCode.NotImplemented;
            }

            if (exception is BusinessException)
            {
                return HttpStatusCode.BadRequest;
            }

            return HttpStatusCode.InternalServerError;
        }
    }
}
